﻿package kliment.data {
	/**
	 * ...
	 * @author	Kliment
	 * @version	1.1.3
	 * 
	 * class name: kliment.data.Directory
	 */
	public class Directory {
		private var _list:Array;
		
		public function Directory() {
			_list = new Array();
		}
		
		public function push(word:Object, value:Object):Boolean {
			if (getValue(word))
				return false;
			_list.push( { word:word,  value:value } );
			return true;
		}
		
		public function add(word:Object, value:*):Boolean {
			return push(word, value);
		}
		
		public function remove(word:Object):Boolean {
			var index:Number = _getItemIndex(word);
			if (index >= 0) {
				_list.splice(index, 1);
				return true;
			}
			return false;
		}
		
		public function getValue(word:Object):* {
			var index:Number = _getItemIndex(word);
			if (index >= 0) 
				return _list[index].value;
			return null;
		}
		
		private function _getItemIndex(word:Object):Number {
			var i:Number = length;
			while (i--) 
				if (_list[i].word == word)
					return i;
			return -1;
		}
		
		public function get length():Number { return _list.length }
			
	}

}